from model.Hero import Hero
from model.events.Event import Event
from view.blockImgs.EventImg import EventImg


class Key(Event):
    dic = {"yellow": "16", "purple": "17", "red": "18"}

    def __init__(self, x_position, y_position, color):
        Event.__init__(self, x_position, y_position)
        self.img_path = "resources/道具/" + Key.dic[color] + ".png"
        self.img = EventImg(self, x_position, y_position)
        self.color = color
        self.isOpening = False
        self.isWork = True
        self.open_step = 0;

    def trigger(self):
        Hero.direction = [0, 0, Hero.direction[2]]
        Hero.step = Hero.step % 4
        if self.color == "yellow":
            Hero.yellowKey += 1
            self.disappear()
        elif self.color == "purple":
            Hero.purpleKey += 1
            self.disappear()
        elif self.color == "red":
            Hero.redKey += 1
            self.disappear()

    def disappear(self):
        self.isWork = False
        self.img_path = "resources/素材/magic_attack0 3.png"
